package com.gxa.service.commlife.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.entity.commlife.CommunityGuides;
import com.gxa.mapper.commlife.CommunityGuidesMapper;
import com.gxa.service.commlife.CommunityGuidesService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:18:00
 */
@Service
public class CommunityGuidesServiceImpl extends ServiceImpl<CommunityGuidesMapper, CommunityGuides> implements CommunityGuidesService {

    @Autowired
    private CommunityGuidesMapper communityGuidesMapper;

    @Override
    public int addCommunityGuides(CommunityGuides communityGuides) {
        int insert = this.communityGuidesMapper.insert(communityGuides);
        return insert;
    }

    @Override
    public  Map<String,Object> queryList(CommunityGuides communityGuides,Integer pageNum, Integer pageSize) {
        Map<String,Object> map = new HashedMap();
        QueryWrapper<CommunityGuides> queryWrapper = new QueryWrapper();
//       if (communityGuides.getLocationName()!=null && communityGuides.getLocationName().equals(" ")){
//           queryWrapper.like("location_name",communityGuides.getLocationName());
//       }
        queryWrapper.like(communityGuides.getLocationName()!=null,"location_name",communityGuides.getLocationName());
       if (communityGuides.getType()!=null && !communityGuides.getType().equals(" ")){
            queryWrapper.eq("cg_type",communityGuides.getType());
        }

        Page<CommunityGuides> page =PageHelper.startPage(pageNum,pageSize);
        List<CommunityGuides> communityGuidesList = this.communityGuidesMapper.selectList(queryWrapper);
        PageInfo<CommunityGuides> pageInfo = new PageInfo<>(communityGuidesList);
        map.put("pageInfo",pageInfo);
        return map;
    }

    @Override
    public int updateCommunityGuides(CommunityGuides communityGuides) {
        int i = this.communityGuidesMapper.updateById(communityGuides);
        return i;
    }

    @Override
    public int deleteCommunityGuides(Integer id) {
        int i = this.communityGuidesMapper.deleteById(id);
        return i;
    }

    @Override
    public CommunityGuides queryById(int id) {
        CommunityGuides communityGuides = this.communityGuidesMapper.selectById(id);
        return communityGuides;
    }

    @Override
    public  Map<String,Object> searchCommunityGuides(CommunityGuides communityGuides,Integer pageNum, Integer pageSize) {
        Map<String,Object> map = new HashedMap();
        QueryWrapper<CommunityGuides> wrapper = new QueryWrapper<>();
        wrapper.likeRight("location_name",communityGuides.getLocationName());
        wrapper.likeRight("type",communityGuides.getType());
        Page<CommunityGuides> page =PageHelper.startPage(pageNum,pageSize);
        List<CommunityGuides> communityGuidesList = this.communityGuidesMapper.selectList(wrapper);
        PageInfo<CommunityGuides> pageInfo = new PageInfo<>(communityGuidesList);
        map.put("pageInfo",pageInfo);
        return map;
    }
}
